﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Elsa.Extensions;
using Elsa.Workflows;
using Elsa.Workflows.Activities;
using Elsa.Workflows.Activities.Flowchart.Models;
using Elsa.Workflows.Attributes;
using Elsa.Workflows.UIHints;
using T.FAS.Runtime.MF.Entity;

namespace T.FAS.Runtime.MF.Activities
{
    public class FasStartActivity : Start
    {
        [Input(Description = "节点的输入信息", UIHint = "switch-editor", Order = 3)]
        public IList<BranchCondition> Inputs { get; set; }

        [Input(Description = "节点运行出参的实时数据")]
        public Dictionary<string, object> OutputInstanceValues { get; set; } = new Dictionary<string, object>();
        [Input(Description = "节点运行入参的实时数据")]
        public Dictionary<string, object> InputInstanceValues { get; set; } = new Dictionary<string, object>();


        protected override async ValueTask ExecuteAsync(ActivityExecutionContext context)
        {
            var variables = context.WorkflowExecutionContext.Workflow.Variables;
            var inputs = context.WorkflowExecutionContext.Input;
            foreach (var variable in variables)
            {
                if (inputs.ContainsKey(variable.Name))
                {
                    context.SetVariable(variable.Name, inputs[variable.Name]);
                    InputInstanceValues[variable.Name] = inputs[variable.Name];
                    OutputInstanceValues[variable.Name] = inputs[variable.Name];
                    //给输入参数赋值
                    context.WorkflowExecutionContext.Input[variable.Name] = inputs[variable.Name]!;
                    context.WorkflowInput[variable.Name] = inputs[variable.Name]!;
                }
            }
           
           ////触发所有端口的后续活动
           //foreach (var outcome in Outcomes??new List<string>())
           //{
           //    await context.CompleteActivityWithOutcomesAsync(new[] { outcome });
           //}
           await context.CompleteActivityWithOutcomesAsync(new[] { "Done" });
        }

      
    }
}
